package com.techstar.ats.codec.history.decoder;

import io.netty.buffer.ByteBuf;
import com.techstar.ats.codec.StringCodec;
import com.techstar.ats.dxp.history.F22InusedTrip;
import com.techstar.ats.dxp.history.rep.F22InusedSchedule;
import com.techstar.ats.type.SubType;

public enum F22InusedScheduleDecoder implements ScheduleDecoder<F22InusedSchedule> {
	INSTANCE;

	public F22InusedSchedule create() {
		return new F22InusedSchedule();
	}

	public void decode(ByteBuf buf, F22InusedSchedule value) {
		ScheduleDecoder.super.decode(buf, value);
		if(SubType.DATA.equals(value.sub)) {
			value.train = (new StringCodec(9)).get(buf);
			int cnt = buf.readUnsignedShort();

			for(int i = 0; i < cnt; ++i) {
				F22InusedTrip trip = F22InusedTripDecoder.INSTANCE.create();
				F22InusedTripDecoder.INSTANCE.decode(buf, trip);
				value.trips.add(trip);
			}
		}

	}
}
